<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ImagesModel extends CI_Model {
    public function saveOrUpdateAvatar($filename, $content_type, $user_id) {
        $image_data = array();
        $image_data['filename'] = $filename;
        $image_data['content_type'] = $content_type;

        $this->db->insert('images', $image_data);
        $image_id = $this->db->insert_id();

        $avatar_data = array();
        $avatar_data['user_id'] = $user_id;
        $avatar_data['image_id'] = $image_id;
        $this->db->insert('avatars', $avatar_data);

        $this->load->model('PostsModel');
        $this->PostsModel->insertPost("avatar_change", null, $user_id);
    }
}